﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;

namespace PRE.Sumary
{
    /// <summary>
    /// Author:		Nguyen Van Toan
    /// Email:		nvt87x@gmail.com
    /// Phone:		01645 515 010
    /// Create:		19/02/2012 08:00 AM
    /// Update:		?
    /// Default form, load all room & room type
    /// </summary>
    public partial class FrmDefault : DevExpress.XtraEditors.XtraForm
    {
        public FrmDefault()
        {
            InitializeComponent();
        }

        private void FrmDefault_Load(object sender, EventArgs e)
        {
            try
            {
                lsvMain.BeginUpdate();
                lsvMain.Clear();
                lsvMain.SmallImageList = imlSmall;
                lsvMain.LargeImageList = imlLarge;

                // Room's status
                lsvMain.Groups.Add(new ListViewGroup("Tình trạng phòng", HorizontalAlignment.Left));
                var sbl = new BLL.StatusBLL();
                var dtb = sbl.Select();
                foreach (DataRow dr in dtb.Rows)
                {
                    ListViewItem listItem = new ListViewItem(dr["Name"] + "") { ImageIndex = UTL.Number.ToInt32(dr["Id"] + "") - 1, Group = lsvMain.Groups[0] };
                    lsvMain.Items.Add(listItem);
                }

                var rbl = new BLL.RoomBLL();
                dtb = rbl.Select();
                lsvMain.Groups.Add(new ListViewGroup("Danh sách phòng", HorizontalAlignment.Left));

                foreach (DataRow dr in dtb.Rows)
                {
                    ListViewItem listItem = new ListViewItem(dr["Name"] + "") { ImageIndex = UTL.Number.ToInt32(dr["StatusId"] + "") - 1 };

                    // Add sub-items for Details view.
                    listItem.SubItems.Add(dr["Id"].ToString());
                    listItem.SubItems.Add(dr["Capacity"].ToString());

                    listItem.Group = lsvMain.Groups[1];
                    lsvMain.Items.Add(listItem);
                }

                // Add column headers for Details view.
                lsvMain.Columns.Add("Tên", 100, HorizontalAlignment.Left);
                lsvMain.Columns.Add("Mã", 100, HorizontalAlignment.Left);
                lsvMain.Columns.Add("Số người", 100, HorizontalAlignment.Left);

                lsvMain.EndUpdate();
            }
            catch { return; }
        }

        private void lsvMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //UTL.Message.Show("Hello", "Xin chao");
            }
        }

        private void lsvMain_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            try
            {
                if (e.IsSelected)
                {
                    var id = UTL.Number.ToInt64(e.Item.SubItems[1].Text); // get room's Id
                    var frm = new Sumary.FrmInfoRoom(id);
                    frm.MyEvent += ReLoadData;

                    frm.MdiParent = MdiParent;
                    frm.Show();
                    //frm.Activate();
                }
            }
            catch { return; }
        }

        private void ReLoadData()
        {
            FrmDefault_Load(null, null);
        }
    }
}